<?php
class filter_relationModel extends baseModel{
    protected $table = 'filter_relation';

    //关联内容
    public function content_relation($data) {
        if(empty($data['filter'])){
            return;
        }
        //删除关联
        $this->del_content_relation($data['aid']);
        foreach ($data['filter'] as $key => $list) {
            if(empty($list)){
                continue;
            }
            $data2 = array() ;
            $data2['fid']=$key;
            $data2['aid']=$data['aid'];
            foreach ($list as $value) {
                $data2['id']=$value;
                $this->insert($data2);
            }
        }
    }
    //获取已选择
    public function get_content_relation($aid,$fid) {
        $list=$this->select('aid='.$aid.' AND fid='.$fid);
        if(!empty($list)){
            foreach ($list as $value) {
                $id[]=$value['id'];
            }
        }
        return $id;
    }


    //删除关联内容
    public function del_content_relation($aid) {
        $this->delete('aid='.$aid);
    }

    //通过类别删除关联
    public function del_relation($fid) {
        $this->delete('fid='.$fid);
    }

    //通过选项删除关联
    public function del_filter_relation($id) {
        $this->delete('id='.$id);
    }
	
}